
package com.borqs.music.tasks;

import static com.borqs.music.http.RequestMethod.GET;
import static com.borqs.music.util.MusicConf.ReqParam.COUNT;
import static com.borqs.music.util.MusicConf.ReqParam.ISFULL;
import static com.borqs.music.util.MusicConf.ReqParam.PAGE;
import static com.borqs.music.util.MusicConf.ReqParam.SINGER;
import static com.borqs.music.util.MusicConf.ReqParam.SORT;
import static com.borqs.music.util.MusicConf.ReqType.MUSIC_ALL;
import static com.borqs.music.util.MusicConf.ReqType.MUSIC_SEARCH_BY_SINGER;

import java.util.HashMap;
import java.util.Map;

import com.borqs.music.executor.TaskListener;
import com.borqs.music.http.HttpRequest;
import com.borqs.music.util.MusicConf;

public class GetAllSongTask extends SongTask {
    public static final String SORT_BY_DOWNLOAD = "download";
    public static final String SORT_BY_LIKE = "like";
    public static final String SORT_BY_LATEST = "createdtime";

    private int mPage;
    private String mSort;
    private String mTicket;
    private String mSingerName;

    public GetAllSongTask(TaskListener listener, String ticket, String singerName, String sort,
            int page,
            boolean isfull) {
        super(listener, isfull);
        this.mTicket = ticket;
        this.mPage = page;
        this.mSort = sort;
        this.mSingerName = singerName;
    }

    public GetAllSongTask(TaskListener listener, String ticket, int page, String singerName) {
        this(listener, ticket, singerName, null, page, false);
    }

    public GetAllSongTask(TaskListener listener, String ticket, String singerName, String sort,
            int page) {
        this(listener, ticket, singerName, sort, page, false);
    }

    @Override
    public HttpRequest prepareRequest() {
        Map<String, String> params = new HashMap<String, String>();
        params.put(PAGE, String.valueOf(mPage));
        if (mSort != null && mSort.length() != 0) {
            params.put(SORT, mSort);
        }

        params.put(COUNT, String.valueOf(PAGE_COUNT));
        params.put(ISFULL, String.valueOf(isFull()));

        HttpRequest req;
        if (null != mSingerName) {
            params.put(SINGER, mSingerName);
            String urlSinger = MusicConf.getUrl(MUSIC_SEARCH_BY_SINGER);
            req = new HttpRequest(GET, urlSinger, mTicket, params);
        } else {
            String urlAllSong = MusicConf.getUrl(MUSIC_ALL);
            req = new HttpRequest(GET, urlAllSong, mTicket, params);
        }

        return req;
    }
}
